package manager.ikaraoke;

import manager.ikaraoke.database.DatabaseHelper;
import manager.ikaraoke.database.dto.FoodDrinkDto;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class SettingAddFoodDrink extends Activity implements OnClickListener{
	private DatabaseHelper databaseHelper;
	private EditText txtName;
	private EditText txtCost;
	private int type;
	private FoodDrinkDto foodDrinkDto;
	private Intent intent;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.add);
		databaseHelper = new DatabaseHelper(getApplicationContext());
		Button btAdd = (Button)findViewById(R.id.btAdd);
		btAdd.setOnClickListener(this);
		Button btCancel = (Button)findViewById(R.id.btCancel);
		btCancel.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v != null) {
			switch (v.getId()) {
			case R.id.btAdd:
				foodDrinkDto = new FoodDrinkDto();
				intent = getIntent();
				type = intent.getIntExtra("type", 0);
				txtName = (EditText) findViewById(R.id.txtName);
				txtCost = (EditText) findViewById(R.id.txtCost);
				foodDrinkDto.setName(txtName.getText().toString());
				foodDrinkDto.setCost(Float.parseFloat(txtCost.getText()
						.toString()));
				foodDrinkDto.setType(type);
				databaseHelper.insertFoodDrink(foodDrinkDto);
				Intent intentBack;
				if(type==1){
					intentBack = new Intent(getApplicationContext(), SettingFood.class);
				}else{
					intentBack = new Intent(getApplicationContext(),SettingDrink.class);
				}
				startActivity(intentBack);
				break;
			case R.id.btCancel:

				break;

			default:
				break;
			}
		}

	}
	

}
